<?php

class My_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $conn = Doctrine_Manager::getInstance()->getConnectionForComponent('User');
        
        $authAdapter = new ZendX_Doctrine_Auth_Adapter(
            $conn,
            'User u',
            'u.username',
            'u.password'
        );
        
        Zend_Registry::set('authAdapter', $authAdapter);
        
        $auth = Zend_Auth::getInstance();
        
        $defaultUserRole = AclRole::getDefault();
        
        if(!$auth->hasIdentity())
        {
            $auth->getStorage()->write(array('Role' => $defaultUserRole));
        }
    }
}